<?php

function dub_slideshow_js($atts)
{
	extract(lAtts(array(
		'path'	=>	'/mooshow/',
		'filename' => array('prototype.lite.js', 'moo.fx.js', 'moo.fx.pack.js')
	),$atts));
	
	$out = '';
	foreach($filename as $js)
		$out .= '<script type="text/javascript" src="'.$path.$js.'"></script>'."\n";
	$out .= '<script type="text/javascript">var showsIE = new Array("myShow");</script> <!-- need this so it can work in IE5.5 -->'."\n";
	return $out;
	
}

function dub_slideshow_css($atts)
{
	extract(lAtts(array(
		'path'	=>	'/mooshow/',
		'filename' => 'mooshow.css',
	),$atts));
	
	return $path.$filename;
}

/* use this in the slideshow photoArray */
function dub_slideshow_images($atts)
{
	extract(lAtts(array(
		'method'		=>	'', // not really used
		'article'		=>	'',
		'category'		=>	'',
		'limit'			=>	15
	),$atts));
	
	global $path_from_root, $img_dir, $thisarticle;

	if (is_array($atts)) {
		extract($atts);
	}

	$out = '';
	$results = array();
	
	// grab images from this article
//	if($method == 'article_image') {
	if(!empty($thisarticle) && empty($category) && empty($article) ) {
		dubug("GETTING FROM THIS ARTICLE");
	  if (!empty($thisarticle['article_image'])) {
			$images = array_slice( split(",", $thisarticle['article_image'], $limit + 1), 0, $limit );
			$rows = safe_rows('*', 'txp_image', 'id in ('.$thisarticle['article_image'].')');
			foreach ($rows as $rs) {
				if ($rs) {
					extract($rs);
					$results[] = $rs;
				}
			}
		}
	}
	// grab all images, in optional category, with optional limit
	else {
		dubug("GETTING ALL/CAT");
		$category_text = '';
		if (!empty($category)) {
			$category_text = "WHERE category = \"$category\"";
		}

		$limit_text = '';
		if (!empty($limit)) {
			$limit_text = "LIMIT $limit";
		}

		$query = "SELECT * FROM txp_image " . $category_text . $limit_text;
		$results = getRows($query,$debug);
		dubug("YO WE DID SOMEHTING COOL");
	}
	
	if ($results) {
		$isfirst = true;
		foreach($results as $image_thumb) {
			extract($image_thumb);

			// for couloir
//			$out .= 'new Array("'.$id.$ext.'", "'.$w.'", "'.$h.'", "'.mysql_escape_string($caption).'")'."\n";

			// for mooshow
			$imgdir = '/images/';
			$size = '100kb';
			$out .= 'new Array("'.$imgdir.$id.$ext.'", "'.$w.'", "'.$h.'", "'.$size.'", "'.mysql_escape_string($alt).'", "'.mysql_escape_string($author).'", "", "'.mysql_escape_string($caption).'"), '."\n";
		}
	} 
	else { 
		return; 
	}


	return $out;
}


/* slideshow WORK! */
function dub_slideshow($atts)
{
	// we pass most of the atts onto dub_slideshow_images during the fetch process
	extract(lAtts(array(
		'debug'			=>	0,
		'usecaption'	=>	0,
		'name'			=>	'slideshow',
		'speed'			=>	200,
		'fadespeed'		=>	400,
		'topNav'		=>	'yes',
		'overlayNav'	=>	'yes',
		'dropShadow'	=>	'no',
		'captions'		=>	'yes',
		'border'		=>	5,
		'copyright'		=>	'no',
		'IPTCinfo'		=>	'no'
	),$atts));	
		
	// generate image array
	$out .= '<script type="text/javascript">'."\n";
	$out .= 'var '.$name.' = new Array('."\n";
	$args = array('method' => 'article_image');
	$out .= dub_slideshow_images($atts);
	$out .= "new Array('', '') \n";
	$out .= ');'."\n";
	$out .= '</script>'."\n";
	
	// include mooshow
	$out .= '<script type="text/javascript" src="/mooshow/mooshow.1.04.js"></script>';
	
	// output the controlling html
	$out .= '<div id="'.$name.'" class="mooshow">';
	$out .= "
		this.speed=$speed;
		this.fadeSpeed=$fadespeed;
		this.topNav='$topNav';
		this.overlayNav='$overlayNav';
		this.dropShadow='$dropShadow';
		this.captions='$captions';
		this.border=$border;
		this.copyright='$copyright';
		this.IPTCinfo='$IPTCinfo';
	</div>";

	return $out;
}

/*
--- PLUGIN METADATA ---
Name: dub_slideshow
Version: 0.1
Type: 0
Description: Interface w/ mooShow moo.fx slideshow code
Author: Jamie Wilkinson
Link: http://tramchase.com
--- BEGIN PLUGIN HELP ---

--- END PLUGIN HELP & METADATA ---
*/
?>